<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <style>
        .fade-enter-active,
        .fade-leave-active {
            transition: opacity 1.5s;
        }
        .fade-enter,
        .fade-leave-to {
            opacity: 0;
        }
    </style>
</head>
<body>
    <!-- 挂载点 -->
    <div id="app">
        <label for="nameInput">姓名</label>
        <input type="text" id="nameInput" v-model="newName" placeholder="请输入姓名">
        <button v-on:click="addName">添加</button>
        <h1>姓名列表</h1>
        <ul>
            <transition-group name="fade">
                <li v-for="(name, index) in names" :key="index" @click="editName(index)">
                    {{ name }}
                    <button @click.stop="deleteName(index)">删除</button>
                </li>
            </transition-group>
        </ul>
    </div>
    <!-- 使用javascript脚本 -->
    <script type="text/javascript">
        new Vue({
            el: "#app",
            data: {
                newName: '',
                names: ['张三', '李四', '王五', '赵四']
            },
            methods: {
                addName() {
                    if (this.newName.trim()) {
                        this.names.push(this.newName.trim());
                        this.newName = '';
                    }
                },
                deleteName(index) {
                    this.names.splice(index, 1);
                },
                editName(index) {
                    const newName = prompt('请输入新的名字', this.names[index]);
                    if (newName) {
                        this.names[index] = newName;
                    }
                }
            }
        })
    </script>
</body>
</html>